package cn.yhp.mybatis.type;

import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

/**
 * jdbc枚举
 * @author yhp
 * @date 2023/12/2
 */
public enum JdbcType {

    INTEGER(Types.INTEGER),
    FLOAT(Types.FLOAT),
    DOUBLE(Types.DOUBLE),
    DECIMAL(Types.DECIMAL),
    VARCHAR(Types.VARCHAR),
    TIMESTAMP(Types.TIMESTAMP);

    public final int TYPE_CODE;

    private static Map<Integer,JdbcType> codeLookup=new HashMap<>();

    // 将所有类型存入map
    static {
        for (JdbcType value : JdbcType.values()) {
            codeLookup.put(value.TYPE_CODE, value);
        }
    }

    JdbcType(int code){
        this.TYPE_CODE=code;
    }

    public static JdbcType forCode(int code)  {
        return codeLookup.get(code);
    }

}
